home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Tool Chest / Hardware / Misc. Tools / LFSR Verilog CAD Tool / LFSR / LFSR.rsrc / TEXT_2000_main.txt < prev    next >
Encoding:
Text File  |  1993-06-03  |  11.2 KB  |  163 lines

  1. `timescale 1 ns / 100 ps
  2. /* Linear Feedback Shift Register 
  3.  * verilog module "¬´font style‚óäbold¬ª¬´field‚óämodule¬ª¬´font style‚óäplain¬ª"
  4.  * Generated by Macintosh application 'LFSR' ¬´date¬ª ¬´time¬ª ¬´if not empty‚óäcompany‚óä
  5.  * company: ¬´field ‚óäcompany¬ª¬ª ¬´if not empty‚óäproject‚óä
  6.  * project: ¬´field ‚óäproject¬ª¬ª ¬´if not empty‚óädesigner‚óä
  7.  * designer: ¬´field ‚óädesigner¬ª¬ª
  8.  * prototypes:
  9.    ¬´font style‚óäbold¬ª¬´field‚óämodule¬ª¬´font style‚óäplain¬ª(¬´field‚óäclock¬ª¬´if true‚ó䬴button‚óäce enable¬ª‚óä, ¬´field‚óäclock enable¬ª¬ª, ¬´field‚óäpreset¬ª¬´if true‚ó䬴button‚óäsr enable¬ª‚óä, ¬´field‚óäshift register output¬ª¬ª¬´if true‚ó䬴button‚óätc enable¬ª‚óä, ¬´field‚óäterminal count¬ª¬ª);
  10.    ¬´font style‚óäbold¬ª¬´field‚óämodule¬ª¬´font style‚óäplain¬ª(.¬´field‚óäclock¬ª(CLOCK)¬´if true‚ó䬴button‚óäce enable¬ª‚óä, .¬´field‚óäclock enable¬ª(CE)¬ª, .¬´field‚óäpreset¬ª(PRESET)¬´if true‚ó䬴button‚óäsr enable¬ª‚óä, .¬´field‚óäshift register output¬ª(Q)¬ª¬´if true‚ó䬴button‚óätc enable¬ª‚óä, .¬´field‚óäterminal count¬ª(TC)¬ª);
  11.  *
  12.  * The counter reaches terminal count after ¬´field‚óäcount¬ª ¬´
  13. if true‚ó䬴button‚óäclock edge polarity¬ª‚óänegative edge‚óäelse‚óäpositive edge¬ª clocks. ¬´if true‚ó䬴button‚óätc enable¬ª‚óä
  14.  * '¬´field ‚óäterminal count¬ª' is asserted ¬´if true‚ó䬴button‚óätc polarity¬ª‚óähigh‚óäelse‚óälow¬ª at the end of count.¬ª
  15.  * count is preset synchronously by an active ¬´if true‚ó䬴button‚óäpreset polarity¬ª‚óähigh‚óäelse‚óälow¬ª on '¬´field‚óäpreset¬ª'.¬´if true‚ó䬴button‚óäretriggerable¬ª‚óä
  16.  * The counter is free running. It presets itself on every terminal count.‚óäelse‚óä
  17.  * The counter stops after terminal count and must be preset to count again.¬ª ¬´if true‚ó䬴button‚óäce enable¬ª‚óä
  18.  * The counting is suspended when '¬´field‚óäclock enable¬ª' is asserted ¬´if true‚ó䬴button‚óäce polarity¬ª‚óähigh‚óäelse‚óälow¬ª.¬ª¬´if true‚ó䬴button‚óäsr enable¬ª‚óä
  19.  * The shift register output of the counter is brought out of the module as '¬´field‚óäshift register output¬ª'.¬ª¬´if true‚ó䬴button‚óäcombinatorial¬ª‚óä
  20.  * The counter uses AND (or NAND) gates on the output of the shift register to detect for terminal count of all 'ones'.‚óäelse‚óä
  21.  * The counter uses small auxiliary counter to detect for terminal count by counting all 'ones' being 
  22.  * shifted into the main counter. The preset of the small auxiliary counter is connected to the 
  23.  * input of the main shift register and terminal count is generated only when ¬´get‚óästages¬ª '1' bits have shifted into the main counter.
  24.  * The auxiliary counter is ¬´get‚óäauxiliary stages¬ª registers with two taps feedback to the input.¬ª
  25.  * The main counter consist of ¬´get‚óästages¬ª registers with ¬´get‚óätap count¬ª taps feedback to the input. 
  26.  */¬´set‚óäauxQ‚óäAUX_¬´field‚óäshift register output¬ª¬ª
  27. module ¬´font style‚óäbold¬ª¬´field‚óämodule¬ª¬´font style‚óäplain¬ª (¬´field‚óäclock¬ª¬´if true‚ó䬴button‚óäce enable¬ª‚óä, ¬´field‚óäclock enable¬ª¬ª, ¬´field‚óäpreset¬ª¬´if true‚ó䬴button‚óäsr enable¬ª‚óä, ¬´field‚óäshift register output¬ª¬ª¬´if true‚ó䬴button‚óätc enable¬ª‚óä, ¬´field‚óäterminal count¬ª¬ª);
  28. input ¬´field‚óäclock¬ª; ¬´if true‚ó䬴button‚óäce enable¬ª‚óä
  29. input ¬´field‚óäclock enable¬ª;¬ª 
  30. input ¬´field‚óäpreset¬ª; ¬´if true‚ó䬴button‚óätc enable¬ª‚óä
  31. output ¬´field‚óäterminal count¬ª;¬ª ¬´set‚óämax‚ó䬴-‚ó䬴get‚óästages¬ª‚óä1¬ª¬ª¬´set‚óäaux max‚ó䬴-‚ó䬴get‚óäauxiliary stages¬ª‚óä1¬ª¬ª¬´if true‚ó䬴button‚óäsr enable¬ª‚óä
  32. output ¬´field‚óäshift register output¬ª;¬ª
  33. reg [¬´get‚óämax¬ª:0] D;
  34. reg  [¬´get‚óämax¬ª:0] ¬´field‚óäshift register output¬ª;¬´if true‚ó䬴button‚óäone shot¬ª‚óä
  35. wire isCounting;¬ª¬´if true‚ó䬴button‚óäauxiliary counter¬ª‚óä
  36. reg [¬´get‚óäaux max¬ª:0] AUX_D;
  37. reg [¬´get‚óäaux max¬ª:0] ¬´get‚óäauxQ¬ª;¬ª
  38.  
  39. assign ¬´field‚óäterminal count¬ª = ¬´if false‚ó䬴button‚óätc polarity¬ª‚óä~¬ª&¬´if true‚ó䬴button‚óäauxiliary counter¬ª‚ó䬴get‚óäauxQ¬ª‚óäelse‚ó䬴field‚óäshift register output¬ª¬ª; ¬´if true‚ó䬴button‚óäone shot¬ª‚óä
  40. assign isCounting = ¬´if false‚ó䬴button‚óäpreset polarity¬ª‚óä~¬ª¬´field‚óäpreset¬ª | (isCounting & ¬´if true‚ó䬴button‚óätc polarity¬ª‚óä~¬ª¬´field‚óäterminal count¬ª);¬ª
  41.  
  42. always @(¬´field‚óäshift register output¬ª or ¬´field‚óäpreset¬ª¬´if true‚ó䬴button‚óäretriggerable¬ª‚óä or ¬´field‚óäterminal count¬ª¬ª¬´if true‚ó䬴button‚óäce enable¬ª‚óä or ¬´field‚óäclock enable¬ª¬ª)
  43.     begin
  44.         casex ({¬´field‚óäpreset¬ª¬´if true‚ó䬴button‚óäretriggerable¬ª‚óä, ¬´field‚óäterminal count¬ª¬ª¬´if true‚ó䬴button‚óäce enable¬ª‚óä, ¬´field‚óäclock enable¬ª¬ª}) // synopsys parallel_case full_case¬´if true‚ó䬴button‚óäce enable¬ª‚óä
  45.             'b?¬´if true‚ó䬴button‚óäretriggerable¬ª‚óä?¬ª¬´if true‚ó䬴button‚óäce enable¬ª‚ó䬴button‚óäce polarity¬ª¬ª:
  46.                 begin
  47.                     D = ¬´field‚óäshift register output¬ª;        // suspend counting
  48.                 end¬ª
  49.             'b¬´button‚óäpreset polarity¬ª¬´if true‚ó䬴button‚óäretriggerable¬ª‚óä?¬ª¬´if true‚ó䬴button‚óäce enable¬ª‚ó䬴not‚ó䬴button‚óäce polarity¬ª¬ª¬ª¬´if true‚ó䬴button‚óäretriggerable¬ª‚óä,            // preset to value
  50.             'b?¬´button‚óätc polarity¬ª¬´if true‚ó䬴button‚óäce enable¬ª‚ó䬴not‚ó䬴button‚óäce polarity¬ª¬ª¬ª¬ª:            // retrigger presets from TC
  51.                 begin
  52.                     D = 'h¬´as hex‚ó䬴get‚óäpreset value¬ª¬ª; // preset to seed
  53.                 end
  54.             'b¬´not‚ó䬴button‚óäpreset polarity¬ª¬ª¬´if true‚ó䬴button‚óäretriggerable¬ª‚ó䬴not‚ó䬴button‚óätc polarity¬ª¬ª¬ª¬´if true‚ó䬴button‚óäce enable¬ª‚ó䬴not‚ó䬴button‚óäce polarity¬ª¬ª¬ª:           // normal counting
  55.                 begin
  56.                     D[¬´get‚óämax¬ª:1] = ¬´field‚óäshift register output¬ª[¬´-‚ó䬴get‚óämax¬ª‚óä1¬ª:0];
  57.                     D[0] = ¬´if true‚ó䬴button‚óäone shot¬ª‚óä(¬ª¬´field‚óäshift register output¬ª[¬´-‚ó䬴get‚óätap0¬ª‚óä1¬ª] ^ ¬´field‚óäshift register output¬ª[¬´-‚ó䬴get‚óätap1¬ª‚óä1¬ª]¬´if true‚ó䬴>‚ó䬴get‚óätap count¬ª‚óä2¬ª‚óä ^ ¬´field‚óäshift register output¬ª[¬´-‚ó䬴get‚óätap2¬ª‚óä1¬ª] ^ ¬´field‚óäshift register output¬ª[¬´-‚ó䬴get‚óätap3¬ª‚óä1¬ª]¬ª¬´if true‚ó䬴button‚óäone shot¬ª‚óä) & isCounting¬ª;
  58.                 end
  59.         endcase
  60.     end // always¬´if true‚ó䬴button‚óäauxiliary counter¬ª‚óä
  61. // Auxiliary counter for detecting terminal count
  62. // counts ¬´get‚óästages¬ª bits of consecutive '1's
  63. always @(D[0] or ¬´field‚óäpreset¬ª¬´if true‚ó䬴button‚óäretriggerable¬ª‚óä or ¬´field‚óäterminal count¬ª¬ª¬´if true‚ó䬴button‚óäce enable¬ª‚óä or ¬´field‚óäclock enable¬ª¬ª)
  64.     begin
  65.         casex ({D[0], ¬´field‚óäpreset¬ª¬´if true‚ó䬴button‚óäretriggerable¬ª‚óä, ¬´field‚óäterminal count¬ª¬ª¬´if true‚ó䬴button‚óäce enable¬ª‚óä, ¬´field‚óäclock enable¬ª¬ª}) // synopsys parallel_case full_case¬´if true‚ó䬴button‚óäce enable¬ª‚óä
  66.             'b??¬´if true‚ó䬴button‚óäretriggerable¬ª‚óä?¬ª¬´if true‚ó䬴button‚óäce enable¬ª‚ó䬴button‚óäce polarity¬ª¬ª:
  67.                 begin
  68.                     AUX_D = ¬´get‚óäauxQ¬ª;        // suspend counting
  69.                 end¬ª
  70.             'b0?¬´if true‚ó䬴button‚óäretriggerable¬ª‚óä?¬ª¬´if true‚ó䬴button‚óäce enable¬ª‚ó䬴not‚ó䬴button‚óäce polarity¬ª¬ª¬ª,            // preset counter if zero detected
  71.             'b?¬´button‚óäpreset polarity¬ª¬´if true‚ó䬴button‚óäretriggerable¬ª‚óä?¬ª¬´if true‚ó䬴button‚óäce enable¬ª‚ó䬴not‚ó䬴button‚óäce polarity¬ª¬ª¬ª¬´if true‚ó䬴button‚óäretriggerable¬ª‚óä,            // preset to value
  72.             'b??¬´button‚óätc polarity¬ª¬´if true‚ó䬴button‚óäce enable¬ª‚ó䬴not‚ó䬴button‚óäce polarity¬ª¬ª¬ª¬ª:            // retrigger presets from TC
  73.                 begin
  74.                     AUX_D = 'h¬´as hex‚ó䬴get‚óäauxiliary preset value¬ª¬ª;
  75.                 end
  76.             'b1¬´not‚ó䬴button‚óäpreset polarity¬ª¬ª¬´if true‚ó䬴button‚óäretriggerable¬ª‚ó䬴not‚ó䬴button‚óätc polarity¬ª¬ª¬ª¬´if true‚ó䬴button‚óäce enable¬ª‚ó䬴not‚ó䬴button‚óäce polarity¬ª¬ª¬ª:           // normal counting
  77.                 begin
  78.                     AUX_D[¬´get‚óäaux max¬ª:1] = ¬´get‚óäauxQ¬ª[¬´-‚ó䬴get‚óäaux max¬ª‚óä1¬ª:0];
  79.                     AUX_D[0] = ¬´if true‚ó䬴button‚óäone shot¬ª‚óä(¬ª¬´get‚óäauxQ¬ª[¬´-‚ó䬴get‚óäauxiliary tap0¬ª‚óä1¬ª] ^ ¬´get‚óäauxQ¬ª[¬´-‚ó䬴get‚óäauxiliary tap1¬ª‚óä1¬ª]¬´if true‚ó䬴button‚óäone shot¬ª‚óä) & isCounting¬ª;
  80.                 end
  81.         endcase
  82.     end // always¬ª
  83.     
  84. // Shift register description
  85. always @(¬´if true‚ó䬴button‚óäclock edge polarity¬ª‚óänegedge‚óäelse‚óäposedge¬ª ¬´field‚óäclock¬ª)
  86.     begin
  87.         ¬´field‚óäshift register output¬ª = D;     // make into D register¬´if true‚ó䬴button‚óäauxiliary counter¬ª‚óä
  88.         ¬´get‚óäauxQ¬ª = AUX_D;     // make into D register¬ª
  89.     end
  90. endmodule // ¬´font style‚óäbold¬ª¬´field‚óämodule¬ª¬´font style‚óäplain¬ª
  91. ¬´if true‚ó䬴button‚óägenerate test module¬ª‚óä
  92. // synopsys translate_off
  93. module LFSR_Test_Counter(clock, ce, preset, tc);
  94. input clock;
  95. input ce;
  96. input preset;
  97. output tc;
  98. reg [31:0] count;
  99.  
  100. assign tc = ~(count == 0);
  101.  
  102. always @(¬´if true‚ó䬴button‚óäclock edge polarity¬ª‚óänegedge‚óäelse‚óäposedge¬ª clock)
  103.     begin
  104.         if(preset == ¬´button‚óäpreset polarity¬ª¬´if true‚ó䬴button‚óäretriggerable¬ª‚óä || count == 0¬ª)
  105.             begin
  106.                 count = ¬´-‚ó䬴field‚óäcount¬ª‚óä1¬ª;
  107.             end
  108.         else if(¬´if true‚ó䬴button‚óäce polarity¬ª‚óä!¬ªce && count >= 0)
  109.             begin
  110.                 count = count - 1;
  111.             end
  112.     end
  113. endmodule // LFSR_Test_Counter
  114. /* The Test module compares the LFSR counter with a conventional decrement counter
  115.  * any discrepancy between the two counters will be displayed
  116.  * The number of clocks to terminal count is always displayed
  117.  */
  118. module Test_¬´field‚óämodule¬ª;
  119.  
  120. reg clock;
  121. reg enable;
  122. reg ce;¬´if true‚ó䬴button‚óäsr enable¬ª‚óä
  123. reg [¬´get‚óämax¬ª:0] Q;¬ª
  124. integer i;
  125. ¬´font style‚óäbold¬ª¬´field‚óämodule¬ª¬´font style‚óäplain¬ª T0(clock¬´if true‚ó䬴button‚óäce enable¬ª‚óä, ce¬ª, enable¬´if true‚ó䬴button‚óäsr enable¬ª‚óä, Q¬ª¬´if true‚ó䬴button‚óätc enable¬ª‚óä, tc¬ª);
  126. LFSR_Test_Counter T1(clock, ce, enable, tc2);
  127. initial
  128.     begin
  129.         i = 0;
  130.         clock = 0;
  131.         ce = ¬´not‚ó䬴button‚óäce polarity¬ª¬ª;
  132.         enable = ¬´button‚óäpreset polarity¬ª;
  133.         #¬´*‚ó䬴get‚óäclock units¬ª‚óä2¬ª
  134.         enable = ¬´not‚ó䬴button‚óäpreset polarity¬ª¬ª; ¬´if true‚ó䬴button‚óäce enable¬ª‚óä
  135.         #¬´*‚ó䬴get‚óäclock units¬ª‚óä4¬ª
  136.         ce = ¬´button‚óäce polarity¬ª;
  137.         #¬´*‚ó䬴get‚óäclock units¬ª‚óä4¬ª
  138.         ce = ¬´not‚ó䬴button‚óäce polarity¬ª¬ª;¬ª
  139.         #¬´*‚ó䬴get‚óämaximum count¬ª‚ó䬴*‚ó䬴get‚óäclock units¬ª‚óä4¬ª¬ª
  140.         $finish;
  141.     end
  142. always
  143.     begin
  144.         #¬´get‚óäclock units¬ª
  145.         clock = ~clock;
  146.     end
  147. always @(posedge clock)
  148.     begin¬´if true‚ó䬴button‚óätc enable¬ª‚óä
  149.          if(tc == ¬´button‚óätc polarity¬ª)
  150.             begin
  151.                 $display("Terminal count occurs at clock #%d", i);
  152.             end
  153.         if(tc != tc2)
  154.             begin
  155.                 $display("Discrepancy between LFSR counter and test counter at clock #%d", i);
  156.                 $display("LFSR terminal count %b, Test terminal count %b",tc, tc2);
  157.             end
  158. //¬ª $display("%d - ce %b, preset %b¬´if true‚ó䬴button‚óätc enable¬ª‚óä ,tc %b¬ª, test tc %b¬´if true‚ó䬴button‚óäsr enable¬ª‚óä, Q %x¬ª", i, ce, enable¬´if true‚ó䬴button‚óätc enable¬ª‚óä, tc¬ª, tc2¬´if true‚ó䬴button‚óäsr enable¬ª‚óä, Q¬ª);
  159.         if(ce) i = i + 1;
  160.     end
  161. endModule // Test_¬´field‚óämodule¬ª
  162. // synopsys translate_on
  163. »